//
//  UserFunctions.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/1/11.
//

import Foundation
import LeanCloud
import SwiftUI

func getUserInfo(id: String, key: String) {
    Task {
        do{
            showLoadPopup()
            showLog("获取用户信息")
            let query = LCQuery(className: "User_")
            query.whereKey(key, .equalTo(id))
            let user =  try await  LeancloudManager.instance.getFirst(query: query, modeType: UserBean.self)
            await MainActor.run {
                userManager.user = nil
                userManager.user = user
                userManager.doLogin()
                showLog(user?.name ?? "")
                hideLoadPopup()
            }
        } catch {
            showLog("获取用户信息失败")
            showLog(error)
            await MainActor.run {
                hideLoadPopup()
            }

        }
    }
}
